<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>无标题文档</title>
    <link href="../../css/style.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="../../js/jquery.js"></script>
        <script type="text/javascript" src="../../js/axios.js"></script>
    <script type="text/javascript" src="../../js/api.js"></script>
</head>

<body>
<div class="place"><span>位置：</span>
    <ul class="placeul">
        <li>采购管理</li>
        <li>采购单审核</li>
        <li>审核</li>
    </ul>
</div>
<div class="formbody">
    <div class="formtitle"><span>采购单审核</span></div>

    <ul class="forminfo">
        <li>
            <label>采购单编号</label>
            <cite id="purchaseId"></cite><!--CG201711180001-->
        </li>
        <li>
            <label>采购购时间</label>
            <cite id="purchaseTime"></cite><!--2017-11-18 15:36:10-->
        </li>
        <li>
            <label>总金额</label>
            <cite id="money"></cite><!--9,876,582-->
        </li>
        <li>
            <label>操作人</label>
            <cite id="auditName"></cite><!--关羽-->
        </li>
    </ul>
    <table class="tablelist">
        <thead>
        <tr>
            <th>序号</th>
            <th>品牌</th>
            <th>类型</th>
            <th>型号</th>
            <th>厂商</th>
            <th>数量</th>
            <th>单位</th>
            <th>单价</th>
            <th>金额</th>
        </tr>
        </thead>
        <tbody id="detaillist">
        <!--                                                                                                                                                                                                                                                                                                                                         <tr>
                      <td>1</td>
                      <td>联想</td>
                      <td>笔记本电脑</td>
                      <td>T470</td>
                      <td>北京联想科技股份有限公司</td>
                      <td>10</td>
                      <td>台</td>
                      <td>9998</td>
                      <td>99980</td>
                  </tr>
                  <tr>
                      <td>2</td>
                      <td>联想</td>
                      <td>笔记本电脑</td>
                      <td>X260</td>
                      <td>北京联想科技股份有限公司</td>
                      <td>5</td>
                      <td>台</td>
                      <td>5500</td>
                      <td>27500</td>
                  </tr>-->
        </tbody>
    </table>
    <ul class="forminfo">
        <li>
            <label>审核意见</label>
            <textarea class="textinput" id="checkOpinion"></textarea>
        </li>
        <li>
            <label>审核状态</label>
            <select class="dfselect" id="checkStatus" >
                <option>--请选择--</option>
                <option value="3">通过</option>
                <option value="4">不通过</option>
            </select>
        </li>
        <li>
            <label>&nbsp;</label>
            <input name="" id="auditPurchase" type="button" class="btn" value="审核"/>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input name="" id="backbutton" type="button" class="btn" value="返回"/>
            <!--onclick="window.location.href='purchaseExamineList.html'"-->
        </li>
    </ul>
</div>
<script type="text/javascript">
    $('.tablelist tbody tr:odd').addClass('odd');
    let parameter1 = getParameter('pageNum');
    let parameter3 = getParameter('condition');
    $('#backbutton').click(() => {
        window.location.href = 'purchaseExamineList.html?pageNum='+parameter1+'&condition='+parameter3
    })
    $(function () {
        loadPurchaseDetail()
    })
    let parameter = getParameter("purchaseId");

    //加载数据
    function loadPurchaseDetail() {

        axiosJson('get', '/purchase/detail', null, {purchaseId: parameter}).then((res) => {
            writePurchaseDetail(res, purchaseId)
        })
    }

    //审核
    $('#auditPurchase').click(function () {
        let opinion = $('#checkOpinion').val();
        let status = $('#checkStatus').val();
        let date = new Date().toLocaleString();
        date=date.replaceAll('/','-')
        if (status!='--请选择--' && opinion !=null){
            axiosJson('get',
                '/purchase/audit',
                null,
                {checkOpinion: opinion, checkStatus: status,checkTime:date,purchaseId: parameter}
            ).then((res)=>{
                alert(res.data.msg)
                window.location.href = 'purchaseExamineList.html?pageNum='+parameter1+'&condition='+parameter3
            })
        }else {
            alert("请完善审核信息！")
        }

    })

    //写数据
    function writePurchaseDetail(res, purchaseId) {
        let pur = res.data.resultData;
        $("#purchaseId").html(pur.purchase.purchaseId)      //采购单编号
        $("#purchaseTime").html(pur.purchase.purchaseTime)  //采购时间
        $("#money").html('￥'+pur.purchase.totalMoney)           //采购总金额
        $("#auditName").html(pur.purchase.creator.uName)    //操作人
        $('#checkOpinion').html(pur.purchase.checkOpinion)  //审核意见

        let pro = pur.purchaseData;
        let str = ''
        for (let i = 0; i < pro.length; i++) {
            str += '<tr>\n' +
                '                <td>' + (i + 1) + '</td>\n' +
                '                <td>' + pro[i].brandName + '</td>\n' +
                '                <td>' + pro[i].typeName + '</td>\n' +
                '                <td>' + pro[i].productModel + '</td>\n' +
                '                <td>' + pro[i].firmName + '</td>\n' +
                '                <td>' + pro[i].count + '</td>\n' +
                '                <td>' + pro[i].productUnit + '</td>\n' +
                '                <td>' + pro[i].purchasePrice + '</td>\n' +
                '                <td>' + pro[i].totalMoney + '</td>\n' +
                '            </tr>'
        }
        $('#detaillist').html(str)
        $('.tablelist tbody tr:odd').addClass('odd');
    }
</script>
</body>
</html>

